//
//  LS_CollectionReusableView.m
//  yiYuanDuoBao
//
//  Created by 罗李苏 on 16/11/25.
//  Copyright © 2016年 罗李苏. All rights reserved.
//

#import "LS_CollectionReusableView.h"
#import "tabBatBtn.h"
#import "LS_getImageUrlModel.h"
#import "XRCarouselView.h"
@interface LS_CollectionReusableView ()

@property (nonatomic, strong) tabBatBtn *fenBtn;
@property (nonatomic, strong) tabBatBtn *tuiBtn;
@property (nonatomic, strong) tabBatBtn *changBtn;
@property (nonatomic, strong) UIView *oneView;
@property (nonatomic, strong) UIView *twoView;
@property (nonatomic, strong) UIView *changView;
@property (nonatomic, strong) UILabel *desLabel;
@property (nonatomic, strong) UIButton *jianBtn;


@end
@implementation LS_CollectionReusableView
-(NSArray *)imageUrlArr{

    if (!_imageUrlArr) {
        _imageUrlArr = [NSArray array];
    }
    return _imageUrlArr;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setSubViews];
        [self getImagrUrlArr];
    }
    return self;
}

- (void)setSubViews{
    //MARK:图片轮播器
//    UIScrollView *scrollView = [[UIScrollView alloc] init];
//    scrollView.contentSize = CGSizeMake(SCREEN_WIDTH * 4, 0);
//    scrollView.bounces = NO;
//    scrollView.showsHorizontalScrollIndicator = NO;
//
//    self.scrollView = scrollView;
//    [self addSubview:scrollView];
//    
//    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.top.equalTo(self);
//        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 188));
//    }];
//    //MARK:轮播图上的imageView 
//    UIImageView *imageView = [[UIImageView alloc] init];
//    self.imageView = imageView;
////    [self addSubview:imageView];
//    [self addSubview:imageView];
//    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.top.equalTo(self);
////        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 188));
//    }];
//    //MARK:分页指示器   0x7fd2bbe24040
//    UIPageControl *control = [[UIPageControl alloc] init];
//    control.numberOfPages = 4;
//    control.pageIndicatorTintColor = [UIColor cyanColor];
//    
//    control.currentPage = 0;
//    control.currentPageIndicatorTintColor = [UIColor redColor];
//    //分页指示器不交互
//    control.userInteractionEnabled = NO;
//
//    //一张图片时隐藏
//    control.hidesForSinglePage = YES;
//    self.control = control;
//    [self addSubview:control];
//    [self.control mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self.imageView).offset(-16);
//        make.bottom.equalTo(self.imageView).offset(-12);
//    }];
    //MARK:图片轮播器
    XRCarouselView *lunView = [[XRCarouselView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 188)];
    self.lunView = lunView;
    NSArray *imagesUrl = @[@"http://mk.wo.com.cn/static/1475138457682.jpg",@"http://mk.wo.com.cn/static/1472694294134.jpg",@"http://mk.wo.com.cn/static/1472694347558.jpg",@"http://mk.wo.com.cn/static/1472693176099.jpg"];
//    NSLog(@"oooooo%@",imagesUrl);
    _lunView.placeholderImage = [UIImage imageNamed:@"XRPlaceholder"];
//    lunView.imageArray = self.imageUrlArr;
    _lunView.imageArray = imagesUrl;
    lunView.time = 2;
    //设置分页控制器的属性
    [lunView setPageImage:[UIImage imageNamed:@"轮播点_默认状态_icon"] andCurrentPageImage:[UIImage imageNamed:@"轮播点_当前状态_icon"]];
    lunView.pagePosition = PositionBottomRight;
//    [lunView setPageColor:[UIColor redColor] andCurrentPageColor:[UIColor greenColor]];
//    [lunView setImageArray:self.imageUrlArr];
    [self addSubview:lunView];
    _lunView = lunView;
//    [self.lunView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.top.equalTo(self);
//        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 188));
//    }];
    
//    MARK:分类按钮
//    tabBatBtn *fenBtn = [tabBatBtn buttonWithImageNmae:@"首页_分类_icon" text:@"分类"];
    tabBatBtn *fenBtn = [[tabBatBtn alloc] initWithFrame:CGRectMake(35, 206, 40, 64)];
    fenBtn.imView.image = [UIImage imageNamed:@"首页_分类_icon"];
    fenBtn.desLabel.text = @"分类";
    self.fenBtn = fenBtn;
    [self addSubview:fenBtn];
//    [self mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self).offset(35);
//        make.top.equalTo(self.lunView.mas_bottom).offset(16);
//    }];
    //MARK:第一个短竖条
    UIView *oneView = [[UIView alloc] initWithFrame:CGRectMake(115, 208, 1, 60)];
    oneView.backgroundColor = [UIColor darkGrayColor];
    self.oneView = oneView;
    [self addSubview:oneView];
//    [self.oneView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.mas_equalTo(CGSizeMake(1, 60));
//        make.left.equalTo(self.fenBtn).offset(40);
//        make.top.equalTo(self.lunView.mas_bottom).offset(18);
//    }];
    //MARK:推荐按钮
//    tabBatBtn *tuiBtn = [tabBatBtn buttonWithImageNmae:@"首页_推荐_icon" text:@"推荐"];
    tabBatBtn *tuiBtn = [[tabBatBtn alloc] initWithFrame:CGRectMake(146, 206, 40, 64)];
    tuiBtn.imView.image = [UIImage imageNamed:@"首页_推荐_icon"];
    tuiBtn.desLabel.text = @"推荐";
    self.tuiBtn = tuiBtn;
    [self addSubview:tuiBtn];
//    [self.tuiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.fenBtn).offset(40);
//        make.top.equalTo(self.lunView.mas_bottom).offset(16);
//    }];
    //MARK:第二个竖短条
    UIView *twoView = [[UIView alloc] initWithFrame:CGRectMake(236, 208, 1, 60)];
    twoView.backgroundColor = [UIColor darkGrayColor];
    self.twoView = twoView;
    [self addSubview:twoView];
//    [self.twoView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.mas_equalTo(CGSizeMake(1, 60));
//        make.left.equalTo(self.tuiBtn).offset(40);
//        make.top.equalTo(self.lunView.mas_bottom).offset(18);
//    }];
    
    //MARK:常见问题按钮
//    tabBatBtn *changBtn = [tabBatBtn buttonWithImageNmae:@"首页_常见问题_icon" text:@"常见问题"];
    tabBatBtn *changBtn = [[tabBatBtn alloc] initWithFrame:CGRectMake(289, 206, 40, 64)];
    changBtn.imView.image = [UIImage imageNamed:@"首页_常见问题_icon"];
    changBtn.desLabel.text = @"常见问题";

    self.changBtn = changBtn;
    [self addSubview: changBtn];
//    [self.changBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.twoView).offset(52);
//        make.top.equalTo(self.lunView.mas_bottom).offset(16);
//
//    }];
    
    //MARK:下面的描述按钮
    UILabel *desLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 314, 42, 16)];
//    [desLabel fsi];
    desLabel.font = [UIFont systemFontOfSize:14];
    desLabel.text = @"分类1";
    self.desLabel = desLabel;
    [self addSubview:desLabel];
//    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self).offset(16);
//        make.top.equalTo(self.fenBtn.mas_bottom).offset(44);
//    }];
    
    //MARK:更多按钮
    UIButton *jianBtn = [[UIButton alloc] initWithFrame:CGRectMake(335, 310, 24, 24)];
    [jianBtn setBackgroundImage:[UIImage imageNamed:@"更多_icon"] forState:UIControlStateNormal];
    [jianBtn addTarget:self action:@selector(jianBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    self.jianBtn = jianBtn;
    [self addSubview:jianBtn];
//    [self.jianBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.changBtn).offset(40);
//        make.right.equalTo(self).offset(-16);
//    }];

    //MARK:长线条
    UIView *changView = [[UIView alloc] initWithFrame:CGRectMake(16, 350, 343, 1)];
    changView.backgroundColor = [UIColor grayColor];
    self.changView = changView;
    [self addSubview:changView];
//    [self.changView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self).offset(16);
//        make.top.equalTo(self.desLabel.mas_bottom).offset(20);
//        make.size.mas_equalTo(CGSizeMake(343, 1));
//    }];
}
    - (void)jianBtnDidClick{
    
        NSLog(@"点击了更多按钮");
    }
- (void )getImagrUrlArr{
    [[AFHTTPSessionManager manager] GET:@"http://wodm.9mobi.cn/api/v1/resource/topshow" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"下载成功,,,,,");
        NSDictionary *dictArr = responseObject[@"data"];
        NSMutableArray *arrM = [NSMutableArray arrayWithCapacity:dictArr.count];
        for (NSDictionary *dict in dictArr) {
            LS_getImageUrlModel *model = [LS_getImageUrlModel getImageUrlModelWithDict:dict];
            [arrM addObject:model.image];
        }
        self.imageUrlArr = arrM.copy;
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"下载失败");
    }];
}
@end
